package num10;

import java.util.HashSet;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Leecode160Best {
    public class ListNode{
        int value;
        ListNode next;

//        public ListNode(int value, ListNode nextNode) {
//            this.value = value;
//            this.nextNode = nextNode;
//        }

        ListNode(int x){
            value = x;
            next = null;

        }
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode pA = headA, pB = headB;
        while (pA != pB) {
            pA = pA == null ? headB : pA.next;
            pB = pB == null ? headA : pB.next;
        }
        return pA;
    }
}
